extends Node

var countries : Array[String] = ["DEFAULT"]
var squads : Dictionary[String , Array]

func _init() -> void:
	var jsonfile = FileAccess.open("res://assets/json/squads.json",FileAccess.READ)
	if jsonfile == null:
		printerr("squal file is not exists")
	
	var json_text := jsonfile.get_as_text()
	var json = JSON.new()
	if json.parse(json_text) != OK:
		printerr("could not parse squad json")
	
	for team in json.data:
		var country_name := team["country"] as String
		countries.append(country_name)
		var players := team["players"] as Array
		if not squads.has(country_name):
			squads.set(country_name, [])
		
		for player in players:
			var full_name := player["name"] as String
			var skin := player["skin"] as Player.SkinColor
			var role := player["role"] as Player.Role
			var speed := player["speed"] as float
			var power := player["power"] as float
			var player_resource := PlayerResource.new(full_name,skin,role,speed,power)
			squads[country_name].append(player_resource)
		assert(players.size() == 6)
	jsonfile.close()

func get_squad(country: String) ->Array:
	if(squads.has(country)):
		return squads[country]
	else:
		return []

func get_countries() -> Array[String]:
	return countries	
